package equipment;

import java.awt.*;

//import java.awt.event.*;
import main.*;

import java.util.ArrayList;

public class Shield extends Equipment {
	
	public Shield() {
		options = new Choice();
		options.setName("Equipment Options");
		options.add("No Shielding");
		options.add("Shielding");
	}
	
	public void applyOptions () {
		if (options.getSelectedItem().equals("Shielding")) {
			// Check that all fighters in the fight can shield
			ArrayList<Unit> allies = null;
			if (owner.armyIndex == Game.GOODINDEX)
				allies = owner.battle.goodUnits;
			else
				allies = owner.battle.badUnits;
			for (Unit u : allies) {
				if (!u.hasEquipment(new Shield())) {
					UI.messageLog.add("Can't shield unless all allies are shielding");
					return;
				}
			}
			UI.messageLog.add(owner.toChoiceString() + " is shielding, all allies are as well");
			for (Unit u : allies) {
				u.setBattleDice(u.getAttacks()*2);
				u.setWoundDice(0);
			}
			/*owner.battleDice = owner.attacks*2;
			owner.woundDice = 0;
			if (owner.armyIndex == Game.GOODINDEX) {
				for (Unit u : owner.battle.goodUnits) {
					if (u.hasEquipment(new Shield()))
						u.battleDice = u.attacks*2;
					else
						u.battleDice = 0;
					u.woundDice = 0;
					u.supporters = new ArrayList<Unit>();
				}
			}*/
		}
	}
	
	public void equipTo(Unit u) {
		this.owner = u;
		u.setDefense(u.getDefense() + 1);
	}
	
	public String toString() {
		return "Shield";
	}
}